package com.itheima.mymap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class demo1 {
    public static void main(String[] args) {
        Map<String, ArrayList<String>> map = new HashMap<>();
        String s1 = "西游记:";
        ArrayList<String> xyj = new ArrayList<>();
        xyj.add("孙悟空");
        xyj.add("唐僧");
        xyj.add("猪八戒");
        xyj.add("沙僧");
        map.put(s1, xyj);

        String s2 = "水浒传:";
        ArrayList<String> shz = new ArrayList<>();
        shz.add("宋江");
        shz.add("李逵");
        shz.add("武松");
        shz.add("林冲");
        map.put(s2, shz);

        Set<String> keys = map.keySet();
        for (String key : keys) {
            ArrayList<String> list = map.get(key);
            System.out.println(key);
            System.out.print("\t");
            int count = 0;
            for (int i = 0; i < list.size(); i++) {
                count++;
                String value = list.get(i);
                if (i == list.size() - 1) {
                    System.out.println(value);
                } else if (i % 2 != 0) {
                    System.out.print(value + "");
                } else {
                    System.out.print(value + ",");
                }
                if (count % 2 == 0 && count != list.size()) {
                    System.out.println();
                    System.out.print("\t");
                }
            }
        }
    }
}
